<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>行内式注入</title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
</head>
<body>
    <div ng-controller="cont">
        <div class="show">{{text}}</div>
        <input type="button" id="btnSum" value="求和" ng-click="onClick(5,10)">
    </div>

    <script>
        /* 定义了一个名为$sum的服务 */
        var app = angular.module('app',[])
            .factory('$sum',function () {
                return {
                    add : function (m,n) {
                        return m + n;
                    }
                };
            })
            .controller('cont',['$scope','$sum',
                function ($scope,$sum) {
                   $scope.onClick = function (m,n) {
                       $scope.text = m + " + " + n + " = " + $sum.add(m,n);
                   }
            }]);

    </script>
</body>
</html>